<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>listenable.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_events_listenable.js.html">listenable.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview An interface for a listenable JavaScript object.
<a name="line17"></a> *
<a name="line18"></a> * WARNING(chrishenry): DO NOT USE! SUPPORT NOT FULLY IMPLEMENTED.
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.events.Listenable&#39;);
<a name="line22"></a>goog.provide(&#39;goog.events.ListenableKey&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.events.EventLike&#39;);
<a name="line25"></a>
<a name="line26"></a>
<a name="line27"></a>
<a name="line28"></a>/**
<a name="line29"></a> * A listenable interface. Also see goog.events.EventTarget.
<a name="line30"></a> * @interface
<a name="line31"></a> */
<a name="line32"></a>goog.events.Listenable = function() {};
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * Whether to use the new listenable interface and mechanism in
<a name="line37"></a> * goog.events and goog.events.EventTarget.
<a name="line38"></a> *
<a name="line39"></a> * TODO(user): Remove this once launched and stable.
<a name="line40"></a> *
<a name="line41"></a> * @type {boolean}
<a name="line42"></a> */
<a name="line43"></a>goog.events.Listenable.USE_LISTENABLE_INTERFACE = false;
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * An expando property to indicate that an object implements
<a name="line48"></a> * goog.events.Listenable.
<a name="line49"></a> *
<a name="line50"></a> * See addImplementation/isImplementedBy.
<a name="line51"></a> *
<a name="line52"></a> * @type {string}
<a name="line53"></a> * @const
<a name="line54"></a> * @private
<a name="line55"></a> */
<a name="line56"></a>goog.events.Listenable.IMPLEMENTED_BY_PROP_ = &#39;__closure_listenable&#39;;
<a name="line57"></a>
<a name="line58"></a>
<a name="line59"></a>/**
<a name="line60"></a> * Marks a given class (constructor) as an implementation of
<a name="line61"></a> * Listenable, do that we can query that fact at runtime. The class
<a name="line62"></a> * must have already implemented the interface.
<a name="line63"></a> * @param {!Function} cls The class constructor. The corresponding
<a name="line64"></a> *     class must have already implemented the interface.
<a name="line65"></a> */
<a name="line66"></a>goog.events.Listenable.addImplementation = function(cls) {
<a name="line67"></a>  cls.prototype[goog.events.Listenable.IMPLEMENTED_BY_PROP_] = true;
<a name="line68"></a>};
<a name="line69"></a>
<a name="line70"></a>
<a name="line71"></a>/**
<a name="line72"></a> * @param {Object} obj The object to check.
<a name="line73"></a> * @return {boolean} Whether a given instance implements
<a name="line74"></a> *     Listenable. The class/superclass of the instance must call
<a name="line75"></a> *     addImplementation.
<a name="line76"></a> */
<a name="line77"></a>goog.events.Listenable.isImplementedBy = function(obj) {
<a name="line78"></a>  return !!(obj &amp;&amp; obj[goog.events.Listenable.IMPLEMENTED_BY_PROP_]);
<a name="line79"></a>};
<a name="line80"></a>
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * Adds an event listener. A listener can only be added once to an
<a name="line84"></a> * object and if it is added again the key for the listener is
<a name="line85"></a> * returned. Note that if the existing listener is a one-off listener
<a name="line86"></a> * (registered via listenOnce), it will no longer be a one-off
<a name="line87"></a> * listener after a call to listen().
<a name="line88"></a> *
<a name="line89"></a> * @param {string} type Event type or array of event types.
<a name="line90"></a> * @param {!Function} listener Callback method, or an object
<a name="line91"></a> *     with a handleEvent function.
<a name="line92"></a> * @param {boolean=} opt_useCapture Whether to fire in capture phase
<a name="line93"></a> *     (defaults to false).
<a name="line94"></a> * @param {Object=} opt_listenerScope Object in whose scope to call the
<a name="line95"></a> *     listener.
<a name="line96"></a> * @return {goog.events.ListenableKey} Unique key for the listener.
<a name="line97"></a> */
<a name="line98"></a>goog.events.Listenable.prototype.listen;
<a name="line99"></a>
<a name="line100"></a>
<a name="line101"></a>/**
<a name="line102"></a> * Adds an event listener that is removed automatically after the
<a name="line103"></a> * listener fired once.
<a name="line104"></a> *
<a name="line105"></a> * If an existing listener already exists, listenOnce will do
<a name="line106"></a> * nothing. In particular, if the listener was previously registered
<a name="line107"></a> * via listen(), listenOnce() will not turn the listener into a
<a name="line108"></a> * one-off listener. Similarly, if there is already an existing
<a name="line109"></a> * one-off listener, listenOnce does not modify the listeners (it is
<a name="line110"></a> * still a once listener).
<a name="line111"></a> *
<a name="line112"></a> * @param {string} type Event type or array of event types.
<a name="line113"></a> * @param {!Function} listener Callback method, or an object
<a name="line114"></a> *     with a handleEvent function.
<a name="line115"></a> * @param {boolean=} opt_useCapture Whether to fire in capture phase
<a name="line116"></a> *     (defaults to false).
<a name="line117"></a> * @param {Object=} opt_listenerScope Object in whose scope to call the
<a name="line118"></a> *     listener.
<a name="line119"></a> * @return {goog.events.ListenableKey} Unique key for the listener.
<a name="line120"></a> */
<a name="line121"></a>goog.events.Listenable.prototype.listenOnce;
<a name="line122"></a>
<a name="line123"></a>
<a name="line124"></a>/**
<a name="line125"></a> * Removes an event listener which was added with listen() or listenOnce().
<a name="line126"></a> *
<a name="line127"></a> * Implementation needs to call goog.events.cleanUp.
<a name="line128"></a> *
<a name="line129"></a> * @param {string} type Event type or array of event types.
<a name="line130"></a> * @param {!Function} listener Callback method, or an object
<a name="line131"></a> *     with a handleEvent function. TODO(user): Consider whether
<a name="line132"></a> *     we can remove Object.
<a name="line133"></a> * @param {boolean=} opt_useCapture Whether to fire in capture phase
<a name="line134"></a> *     (defaults to false).
<a name="line135"></a> * @param {Object=} opt_listenerScope Object in whose scope to call
<a name="line136"></a> *     the listener.
<a name="line137"></a> * @return {boolean} Whether any listener was removed.
<a name="line138"></a> */
<a name="line139"></a>goog.events.Listenable.prototype.unlisten;
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * Removes an event listener which was added with listen() by the key
<a name="line144"></a> * returned by listen().
<a name="line145"></a> *
<a name="line146"></a> * Implementation needs to call goog.events.cleanUp.
<a name="line147"></a> *
<a name="line148"></a> * @param {goog.events.ListenableKey} key The key returned by
<a name="line149"></a> *     listen() or listenOnce().
<a name="line150"></a> * @return {boolean} Whether any listener was removed.
<a name="line151"></a> */
<a name="line152"></a>goog.events.Listenable.prototype.unlistenByKey;
<a name="line153"></a>
<a name="line154"></a>
<a name="line155"></a>/**
<a name="line156"></a> * Dispatches an event (or event like object) and calls all listeners
<a name="line157"></a> * listening for events of this type. The type of the event is decided by the
<a name="line158"></a> * type property on the event object.
<a name="line159"></a> *
<a name="line160"></a> * If any of the listeners returns false OR calls preventDefault then this
<a name="line161"></a> * function will return false.  If one of the capture listeners calls
<a name="line162"></a> * stopPropagation, then the bubble listeners won&#39;t fire.
<a name="line163"></a> *
<a name="line164"></a> * @param {goog.events.EventLike} e Event object.
<a name="line165"></a> * @return {boolean} If anyone called preventDefault on the event object (or
<a name="line166"></a> *     if any of the listeners returns false this will also return false.
<a name="line167"></a> */
<a name="line168"></a>goog.events.Listenable.prototype.dispatchEvent;
<a name="line169"></a>
<a name="line170"></a>
<a name="line171"></a>/**
<a name="line172"></a> * Removes all listeners from this listenable. If type is specified,
<a name="line173"></a> * it will only remove listeners of the particular type. otherwise all
<a name="line174"></a> * registered listeners will be removed.
<a name="line175"></a> *
<a name="line176"></a> * Implementation needs to call goog.events.cleanUp for each removed
<a name="line177"></a> * listener.
<a name="line178"></a> *
<a name="line179"></a> * @param {string=} opt_type Type of event to remove, default is to
<a name="line180"></a> *     remove all types.
<a name="line181"></a> * @return {number} Number of listeners removed.
<a name="line182"></a> */
<a name="line183"></a>goog.events.Listenable.prototype.removeAllListeners;
<a name="line184"></a>
<a name="line185"></a>
<a name="line186"></a>/**
<a name="line187"></a> * Fires all registered listeners in this listenable for the given
<a name="line188"></a> * type and capture mode, passing them the given eventObject. This
<a name="line189"></a> * does not perform actual capture/bubble. Only implementors of the
<a name="line190"></a> * interface should be using this.
<a name="line191"></a> *
<a name="line192"></a> * @param {string} type The type of the listeners to fire.
<a name="line193"></a> * @param {boolean} capture The capture mode of the listeners to fire.
<a name="line194"></a> * @param {goog.events.Event} eventObject The event object to fire.
<a name="line195"></a> * @return {boolean} Whether all listeners succeeded without
<a name="line196"></a> *     attempting to prevent default behavior. If any listener returns
<a name="line197"></a> *     false or called goog.events.Event#preventDefault, this returns
<a name="line198"></a> *     false.
<a name="line199"></a> */
<a name="line200"></a>goog.events.Listenable.prototype.fireListeners;
<a name="line201"></a>
<a name="line202"></a>
<a name="line203"></a>/**
<a name="line204"></a> * Gets all listeners in this listenable for the given type and
<a name="line205"></a> * capture mode.
<a name="line206"></a> *
<a name="line207"></a> * @param {string} type The type of the listeners to fire.
<a name="line208"></a> * @param {boolean} capture The capture mode of the listeners to fire.
<a name="line209"></a> * @return {!Array.&lt;goog.events.ListenableKey&gt;} An array of registered
<a name="line210"></a> *     listeners.
<a name="line211"></a> */
<a name="line212"></a>goog.events.Listenable.prototype.getListeners;
<a name="line213"></a>
<a name="line214"></a>
<a name="line215"></a>/**
<a name="line216"></a> * Gets the goog.events.ListenableKey for the event or null if no such
<a name="line217"></a> * listener is in use.
<a name="line218"></a> *
<a name="line219"></a> * @param {string} type The name of the event without the &#39;on&#39; prefix.
<a name="line220"></a> * @param {!Function} listener The listener function to get.
<a name="line221"></a> * @param {boolean=} capture Whether the listener is a capturing listener.
<a name="line222"></a> * @param {Object=} opt_listenerScope Object in whose scope to call the
<a name="line223"></a> *     listener.
<a name="line224"></a> * @return {goog.events.ListenableKey} the found listener or null if not found.
<a name="line225"></a> */
<a name="line226"></a>goog.events.Listenable.prototype.getListener;
<a name="line227"></a>
<a name="line228"></a>
<a name="line229"></a>
<a name="line230"></a>/**
<a name="line231"></a> * Whether there is any active listeners matching the specified
<a name="line232"></a> * signature. If either the type or capture parameters are
<a name="line233"></a> * unspecified, the function will match on the remaining criteria.
<a name="line234"></a> *
<a name="line235"></a> * @param {string=} opt_type Event type.
<a name="line236"></a> * @param {boolean=} opt_capture Whether to check for capture or bubble
<a name="line237"></a> *     listeners.
<a name="line238"></a> * @return {boolean} Whether there is any active listeners matching
<a name="line239"></a> *     the requested type and/or capture phase.
<a name="line240"></a> */
<a name="line241"></a>goog.events.Listenable.prototype.hasListener;
<a name="line242"></a>
<a name="line243"></a>
<a name="line244"></a>
<a name="line245"></a>/**
<a name="line246"></a> * An interface that describes a single registered listener.
<a name="line247"></a> * @interface
<a name="line248"></a> */
<a name="line249"></a>goog.events.ListenableKey = function() {};
<a name="line250"></a>
<a name="line251"></a>
<a name="line252"></a>/**
<a name="line253"></a> * Counter used to create a unique key
<a name="line254"></a> * @type {number}
<a name="line255"></a> * @private
<a name="line256"></a> */
<a name="line257"></a>goog.events.ListenableKey.counter_ = 0;
<a name="line258"></a>
<a name="line259"></a>
<a name="line260"></a>/**
<a name="line261"></a> * Reserves a key to be used for ListenableKey#key field.
<a name="line262"></a> * @return {number} A number to be used to fill ListenableKey#key
<a name="line263"></a> *     field.
<a name="line264"></a> */
<a name="line265"></a>goog.events.ListenableKey.reserveKey = function() {
<a name="line266"></a>  return ++goog.events.ListenableKey.counter_;
<a name="line267"></a>};
<a name="line268"></a>
<a name="line269"></a>
<a name="line270"></a>/**
<a name="line271"></a> * The source event target.
<a name="line272"></a> * @type {!(Object|goog.events.Listenable|goog.events.EventTarget)}
<a name="line273"></a> */
<a name="line274"></a>goog.events.ListenableKey.prototype.src;
<a name="line275"></a>
<a name="line276"></a>
<a name="line277"></a>/**
<a name="line278"></a> * The event type the listener is listening to.
<a name="line279"></a> * @type {string}
<a name="line280"></a> */
<a name="line281"></a>goog.events.ListenableKey.prototype.type;
<a name="line282"></a>
<a name="line283"></a>
<a name="line284"></a>/**
<a name="line285"></a> * The listener function.
<a name="line286"></a> * TODO(user): Narrow the type if possible.
<a name="line287"></a> * @type {Function|Object}
<a name="line288"></a> */
<a name="line289"></a>goog.events.ListenableKey.prototype.listener;
<a name="line290"></a>
<a name="line291"></a>
<a name="line292"></a>/**
<a name="line293"></a> * Whether the listener works on capture phase.
<a name="line294"></a> * @type {boolean}
<a name="line295"></a> */
<a name="line296"></a>goog.events.ListenableKey.prototype.capture;
<a name="line297"></a>
<a name="line298"></a>
<a name="line299"></a>/**
<a name="line300"></a> * The &#39;this&#39; object for the listener function&#39;s scope.
<a name="line301"></a> * @type {Object}
<a name="line302"></a> */
<a name="line303"></a>goog.events.ListenableKey.prototype.handler;
<a name="line304"></a>
<a name="line305"></a>
<a name="line306"></a>/**
<a name="line307"></a> * A globally unique number to identify the key.
<a name="line308"></a> * @type {number}
<a name="line309"></a> */
<a name="line310"></a>goog.events.ListenableKey.prototype.key;
</pre>


</body>
</html>
